package com.game.centerserver.common;

import cn.hutool.http.HttpStatus;
import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 * 响应类
 * @Author: tian
 * @Date: 2024/11/17/16:02
 * @Description:
 */
@Data
public class Result<T> {
    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    public static Result ok(String message){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(HttpStatus.HTTP_OK);
        result.setMessage(message);
        return result;
    }

    public static <T> Result ok(String message,T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(HttpStatus.HTTP_OK);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static Result fail(String message){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(HttpStatus.HTTP_INTERNAL_ERROR);
        result.setMessage(message);
        return result;
    }

    public static <T> Result fail(String message,T data){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(HttpStatus.HTTP_INTERNAL_ERROR);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
}
